<template>
  <q-page>
    <div class="container">
      <q-form autofocus @submit="doLogin">
        <div class="row q-col-gutter-md">
          <div class="col-12">
            <q-input label="用户名" v-model="username"/>
          </div>
          <div class="col-12">
            <q-input label="密码" type="password" v-model="password"/>
          </div>
          <div class="col-12">
            <q-btn type="submit" color="primary" label="登录" />
          </div>
        </div>
      </q-form>
    </div>
  </q-page>
</template>

<script>
import Account from "src/lib/api/account";

export default {
  name: "Login",
  data: function () {
    return {
      username: '',
      password: ''
    };
  },
  methods: {
    async doLogin () {
      this.$q.loading.show({
        message: '正在登录，请稍候……'
      });
      try {
        if (await Account.login(this.username, this.password)) await this.$router.push('/account/me');
      } catch {}
      this.$q.loading.hide();
    }
  }
}
</script>

<style scoped>

</style>
